<!DOCTYPE html>
<html ng-app='expanderModule'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

    <title>directive</title>

    <script type="text/javascript" src="/resources/js/angular.js"></script>

    <script type="text/javascript">

        var expanderModule=angular.module('expanderModule', [])
        expanderModule.directive('expander', function() {
            return {
                restrict : 'EA',
                replace : true,
                transclude : true,
                scope : {
                    title : '=expanderTitle'
                },
                template : '<div>'
                + '<div class="title" ng-click="toggle()">{{title}}</div>'
                + '<div class="body" ng-show="showMe" ng-transclude></div>'
                + '</div>',
                link : function(scope, element, attrs) {
                    scope.showMe = false;
                    scope.toggle = function toggle() {
                        scope.showMe = !scope.showMe;
                    }
                }
            }
        });
        expanderModule.controller('SomeController',function($scope) {
            $scope.title = '点击展开';
            $scope.text = '这里是内部的内容。';
        });

    </script>

    <style type="text/css">
        .expander {
            border: 1px solid black;
            width: 250px;
        }

        .expander>.title {
            background-color: black;
            color: white;
            padding: .1em .3em;
            cursor: pointer;
        }

        .expander>.body {
            padding: .1em .3em;
        }


    </style>
</head>
<body>
<div ng-controller='SomeController'>
    <expander class='expander' expander-title='title'>
        {{text}}
    </expander>
</div>
</body>
</html>